package com.hcbd.tdwt.ui.setting.xingyu.activity;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;


import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.BaseActivity;
import com.hcbd.tdwt.base.Constant;
import com.hcbd.tdwt.base.GlobalParams;
import com.hcbd.tdwt.util.SharedPreferencesUtil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.CheckedChange;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@SuppressLint("NonConstantResourceId")
@EActivity(R.layout.activity_channel_set)
public class ChannelSetActivity extends BaseActivity {
    @ViewById
    Button implementBtn;
    @ViewById
    RadioButton changeOne,changeTwo,customRb;
    @ViewById
    EditText customEt;
    private SharedPreferencesUtil sp;

    @AfterViews
    protected void init() {
        sp=new SharedPreferencesUtil(this);
        String number=sp.getAttribute(Constant.PLATFORM_CENTER_NUMBER);
        if(Constant.PLATFORM_2.equals(number)){
            changeOne.setChecked(true);
        }else if(Constant.PLATFORM_3.equals(number)){
            changeTwo.setChecked(true);
        }else{
            customRb.setChecked(true);
            customEt.setText(number);
        }
    }
    @CheckedChange
    void customRb(boolean isCheck){
        if(isCheck){
            customEt.setVisibility(View.VISIBLE);
        }else{
            customEt.setVisibility(View.GONE);
        }
    }
    @Click
    void implementBtn(){
        if(changeOne.isChecked()){
            sp.addAttribute(Constant.PLATFORM_CENTER_NUMBER,Constant.PLATFORM_2);
            GlobalParams.rdCentreNumber=Constant.PLATFORM_2;
        }else if(changeTwo.isChecked()){
            sp.addAttribute(Constant.PLATFORM_CENTER_NUMBER,Constant.PLATFORM_3);
            GlobalParams.rdCentreNumber=Constant.PLATFORM_3;
        }else if(customRb.isChecked()){
            String customTxt=getTextStr(customEt);
            if("".equals(customTxt)){
                toast("请输入自定义的通道号码!");
                return;
            }
            sp.addAttribute(Constant.PLATFORM_CENTER_NUMBER,customTxt);
            GlobalParams.rdCentreNumber=customTxt;
        }else{
            toast("请选择通道号");
            return;
        }
        toast("保存成功");
        finish();
    }

    @Click
    void headLeft(){
        finish();
    }
}
